import cv2
import numpy as np
import os
from config import get_settings

"""
生成测试视频
"""

settings = get_settings()
# 视频参数设置
frame_width = 1920
frame_height = 1080
fps = 30  # 帧率
duration_seconds = 10
fourcc = cv2.VideoWriter_fourcc(*'mp4v')  # 使用MP4V编码器（也可以选择其他编码器）

# 创建VideoWriter对象

out_file = os.path.join(settings.BASE_DIR, "static", "test_video.mp4")
video_writer = cv2.VideoWriter(out_file, fourcc, fps, (frame_width, frame_height))

# 计算总共需要多少帧
total_frames = fps * duration_seconds

# 生成并写入帧
for i in range(total_frames):
    # 创建一个全黑的帧
    frame = np.zeros((frame_height, frame_width, 3), dtype=np.uint8)
    
    # 进行颜色空间转换
    hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    
    # 将转换后的帧写入视频文件
    video_writer.write(hsv_frame)

# 关闭视频写入
video_writer.release()

print("Test video has been successfully generated.")